package com.djl.zenithbite.repository.impl;


import com.djl.zenithbite.dto.request.shopping.ShoppingQueryRequest;
import com.djl.zenithbite.entity.Product;
import com.djl.zenithbite.entity.ProductExample;
import com.djl.zenithbite.repository.ProductMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ProductRepositoryImpl {

    @Autowired
    private ProductMapper productMapper;

    public List<Product> queryProduct(ShoppingQueryRequest request){
        ProductExample example = new ProductExample();
        ProductExample.Criteria criteria = example.createCriteria();
        example.setOrderByClause("updated_at desc");
        if (StringUtils.isNotBlank(request.getProductName())){
            criteria.andProductNameLike("%" + request.getProductName() + "%");
        }

        return productMapper.selectByExample(example);
    }

}
